package com.unbook.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResponseVo<T>{
    private Integer code;
    private String msg;
    private T data;
    private String token;
    private ResponseVo(Integer code,T data, String msg){
        this.code = code;
        this.data = data;
        this.msg = msg;
    }
    private ResponseVo(Integer code, T data, String msg, String token){
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.token = token;
    }
    public static <T> ResponseVo<T> success(){
        return new ResponseVo<>(ResponseEnum.SUCCESS.getCode(),null,ResponseEnum.SUCCESS.getDesc());
    }
    public static <T> ResponseVo<T> success(T data){
        return new ResponseVo<>(ResponseEnum.SUCCESS.getCode(),data,ResponseEnum.SUCCESS.getDesc());
    }
    public static <T> ResponseVo<T> success(T data, String token){
        return new ResponseVo<>(ResponseEnum.SUCCESS.getCode(),data,ResponseEnum.SUCCESS.getDesc(), token);
    }
    public static <T> ResponseVo<T> error(){
        return new ResponseVo<>(ResponseEnum.SERVER_ERR.getCode(), null, ResponseEnum.SERVER_ERR.getDesc());
    }
    public static <T> ResponseVo<T> error(ResponseEnum err){
        return new ResponseVo<>(err.getCode(), null, err.getDesc());
    }
    public static <T> ResponseVo<T> error(String msg){
        return new ResponseVo<>(ResponseEnum.SERVER_ERR.getCode(), null, msg);
    }
    public static <T> ResponseVo<T> paramsErr(){
        return new ResponseVo<>(ResponseEnum.PARAM_ERR.getCode(), null, ResponseEnum.PARAM_ERR.getDesc());
    }
    public static <T> ResponseVo<T> insertErr(){
        return new ResponseVo<>(ResponseEnum.INSERT_ERR.getCode(), null, ResponseEnum.INSERT_ERR.getDesc());
    }
    public static <T> ResponseVo<T> updateErr(){
        return new ResponseVo<>(ResponseEnum.UPDATE_ERR.getCode(), null, ResponseEnum.UPDATE_ERR.getDesc());
    }
    public static <T> ResponseVo<T> deleteErr(){
        return new ResponseVo<>(ResponseEnum.UPDATE_ERR.getCode(), null, ResponseEnum.UPDATE_ERR.getDesc());
    }
    public static <T> ResponseVo<T> authErr(String msg){
        return new ResponseVo<>(ResponseEnum.UPDATE_ERR.getCode(), null, msg);
    }
    public static <T> ResponseVo<T> authErr(){
        return authErr(ResponseEnum.AUTH_ERR.getDesc());
    }
    public static <T> ResponseVo<T> custom(Integer code, String msg){
        return new ResponseVo<T>(code, null, msg);
    }
}
